<?php

class Application_Model_KurierMapper
{

    protected $_dbTable;

    public function init()
    {
        $this->_dbTable = new Application_Model_DbTable_Kurier();
    }

    public function setDbTable($dbTable)
    {
        $dbTable = new $dbTable();

        if (!$dbTable instanceof Zend_Db_Table_Abstract)
        {
            throw new Exception('Invalid table data gateway provided');
        }

        $this->_dbTable = $dbTable;
        return $this;
    }

    public function getDbTable()
    {
        if (null == $this->_dbTable)
        {
            $this->setDbTable('Application_Model_DbTable_Kurier');
        }
        return $this->_dbTable;
    }

    public function podajKurierow()
    {
        $resultSet = $this->getDbTable()->fetchAll();

        $kurierzy = array();

        foreach ($resultSet as $row)
        {
            $kurier = new Application_Model_Kurier();

            $kurier->setIdKur($row->id_kur)
                    ->setMiasto($row->miasto);

            $kurierzy[] = $kurier;
        }
        return $kurierzy;
    }

    public function podajKierunek($id, Application_Model_Kurier $kurier)
    {
        $resultSet = $this->getDbTable()->find($id);
        $row = $resultSet->current();

        $kurier->setIdKur($row['id_kier']);
        $kurier->setMiasto($row['miasto']);
    }

   

}

